package com.fowo.api.controller;

import com.alibaba.fastjson.JSONObject;
import com.fowo.api.common.model.R;
import com.fowo.api.model.lingxing.ProductInfoBatchDto;
import com.fowo.api.model.warehouse.WarehouseVo;
import com.fowo.api.service.LingXingInterfaceService;
import com.fowo.api.service.WarehouseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author: <a href="1006319834@qq.com">王冰卿</a>
 * @Description:
 * @Version: 1.0
 * @Date: Created in 2023/3/19 23:51
 * @Modified By:
 */
@Tag(name = "领星接口")
@RequestMapping("/api/lingxing-interface")
@RestController
public class LingXingInterfaceController {

	@Resource
	private LingXingInterfaceService service;
	@Resource
	private WarehouseService warehouseService;

	/**
	 * 同步产品
	 * @return
	 */
	@Operation(summary = "同步产品")
	@RequestMapping("/sync-product")
	public R syncProduct(){
		return R.run(() -> service.syncProduct());
	}

	/**
	 * 同步入库单
	 * @return
	 */
	@Operation(summary = "同步入库单")
	@RequestMapping("/sync-stockIn")
	public R syncStockIn(){
		return R.run(() -> service.syncStockIn());
	}

	/**
	 * 同步出库单
	 * @return
	 */
	@Operation(summary = "同步出库单")
	@RequestMapping("/sync-StockOut")
	public R syncStockOut(){
		return R.run(() -> service.syncStockOut());
	}

	/**
	 * 同步本地仓库期初库存
	 * @return
	 */
	@Operation(summary = "同步本地仓库期初库存")
	@PostMapping("/sync-localInventory")
	public R syncStock(){
		return R.run(() -> service.syncLocalInventory());
	}

	/**
	 * 同步本地仓库期初库存
	 * @return
	 */
	@Operation(summary = "同步FBA仓库期初库存")
	@PostMapping("/sync-fbaInventory")
	public R syncFbaStock(){
		return R.run(() -> service.syncFbaInventory());
	}

	@Operation(summary = "同步店铺信息")
	@PostMapping("/sync-shop")
	public R syncShop(){
		return R.run(() -> service.syncShop());
	}


	@Operation(summary = "同步供应商信息")
	@PostMapping("/sync-supplier")
	public R syncSupplier(){
		return R.run(() -> service.syncSupplier());
	}
	/**
	 * 同步利润报表-店铺
	 * @return
	 */
	@Operation(summary = "同步利润报表-店铺")
	@PostMapping("/sync-shopProfit")
	public R syncShopProfit(){
		return R.run(() -> service.syncShopProfit(null));
	}

	@Operation(summary = "同步销售出库单信息")
	@PostMapping("/sync-salesOutbound")
	public R syncSalesOutbound(){
		return R.run(() -> service.syncSalesOutbound());
	}

	@Operation(summary = "更新同步仓库列表")
	@PostMapping("/sync-warehouse")
	public R syncWarehouse(){
		return R.run(() -> service.syncWarehouse());
	}

	@Operation(summary = "更新同步仓位列表")
	@PostMapping("/sync-warehouseBin")
	public R syncWarehouseBin(@RequestBody JSONObject wid) throws Exception {
//		WarehouseVo wid1 = warehouseService.getVoById(wid.getLong("wid"));
//		Assert.notNull(wid1,"仓库不存在");
//		Assert.notNull(wid1.getWid(),"没有可同步的仓位");
//		wid.put("wid",wid1.getWid());
		//Assert.notNull(null,"此功能已取消");
		return R.run(() -> service.syncWarehouseBin(wid));
	}


	@Operation(summary = "同步销售出库单信息")
	@PostMapping("/update-salesOutbound")
	public R updateSalesOutbound(){
		service.updateSalesOutboundOne();
		service.updateSalesOutboundTwo();
		service.updateSalesOutboundThree();
		service.updateSalesOutboundFour();
		return R.run(() -> service.updateSalesOutbound());
	}

	@Operation(summary = "拉取用户")
	@PostMapping("/getCustomer")
	public R getCustomer(){
		return R.run(() -> service.getCustomer());
	}

	@Operation(summary = "同步亚马逊订单（默认三天）")
	@GetMapping("/orderThreeDays")
	public R insertOrderThreeDays(){
		return R.run(() -> service.syncAmazonOrderList());
	}

	@Operation(summary = "同步亚马逊订单")
	@PostMapping("/syncOrder")
	public R insertOrder(JSONObject object){
		return R.run(() -> service.syncAmazonOrderList1(object));
	}

	@GetMapping("/productInfo")
	public R syncProductInfo(String sku,Integer id){
		return R.run(() -> service.syncProductInfo(sku, id));
	}

	@Operation(summary = "批量获取产品详情")
	@PostMapping("/productInfoBatch")
	public R syncProductInfoBatch(@RequestBody String sku){
		return R.run(() -> service.syncProductInfoBatch(sku));
	}

	@Operation(summary = "销售统计")
	@GetMapping("/syncSalesDaily")
	public R syncSalesDailyList(int year,int month){
		return R.run(() -> service.syncSalesDailyList(year, month));
	}

	@Operation(summary = "FBA库存数据")
	@GetMapping("/syncFBAInventory")
	public R syncFBAInventory(){
		return R.run(() -> service.syncFBAInventory());
	}

	@Operation(summary = "根据创建时间同步并更新产品")
	@PostMapping("/syncByTime")
	public R syncByTimeProduct(JSONObject object){
		return R.run(() -> service.syncByTimeProduct(object));
	}

	@GetMapping("/syncByCreateTime")
	public R syncByCreateTimeProduct(){
		return R.run(() -> service.syncByCreateTimeProduct());
	}

	@GetMapping("/syncByUpdateTime")
	public R syncByUpdateTimeProduct(){
		return R.run(() -> service.syncByUpdateTimeProduct());
	}

	@GetMapping("/syncClassify")
	public R syncClassify(){
		return R.run(() -> service.syncClassify());
	}
}
